//package com.hitqz.robot.camera;
//
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.io.FileUtil;
//import cn.hutool.core.util.RandomUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.extra.spring.SpringUtil;
//import cn.hutool.json.JSONObject;
//import cn.hutool.json.XML;
//import cn.hutool.system.SystemUtil;
//import com.hitqz.robot.camera.callback.HkAlarmMessageCallBack;
//import com.hitqz.robot.camera.callback.HkTemperatureCallBack;
//import com.hitqz.robot.camera.configure.CameraProperties;
//import com.hitqz.robot.camera.dto.*;
//import com.hitqz.robot.camera.entity.ConstantsFace;
//import com.hitqz.robot.camera.entity.HkCameraDriver;
//import com.hitqz.robot.camera.entity.TemplateArea;
//import com.hitqz.robot.camera.exception.EquipmentException;
//import com.hitqz.robot.camera.service.HCNetSDK;
//import com.hitqz.robot.camera.service.PlayCtrl;
//import com.hitqz.robot.camera.type.EquipmentEnum;
//import com.sun.jna.Memory;
//import com.sun.jna.Native;
//import com.sun.jna.Pointer;
//import com.sun.jna.ptr.IntByReference;
//import jakarta.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.dom4j.Document;
//import org.dom4j.DocumentHelper;
//import org.dom4j.Element;
//import org.dom4j.io.SAXReader;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.boot.autoconfigure.web.ServerProperties;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.*;
//import java.util.stream.Collectors;
//import java.util.stream.IntStream;
//
///**
// * @author kehanjiang
// * @date 2024/08/15
// */
//@Slf4j
//@Service("HkCameraService")
//public class HkCameraService implements ICameraService, CommandLineRunner {
//
//    private static HCNetSDK hcNetSDK;
//
//    private SAXReader saxReader = new SAXReader();
//
//    @Resource
//    private CameraProperties properties;
//
//    private String rootDir = System.getProperty("user.dir");
//
//    @Resource
//    private ServerProperties serverProperties;
//
//    @Override
//    public boolean intSdk() {
//        boolean result = true;
//        if (ConstantsFace.HK_NET_SDK == null) {
//            if (!createSDKInstance()) {
//                log.error("[HK]netSdk初始化失败----------");
//                result = false;
//            } else {
//                log.info("[HK]netSdk载入成功----------");
//                hcNetSDK = ConstantsFace.HK_NET_SDK;
//                //初始设置
//                hcNetSDK.NET_DVR_Init();
//                hcNetSDK.NET_DVR_SetConnectTime(2000, 3);
//                hcNetSDK.NET_DVR_SetReconnect(10000, true);
//                String path = Optional.ofNullable(properties.getHk().getLogPath()).orElse(rootDir) + File.separator + "sdkLog" + File.separator;
//                hcNetSDK.NET_DVR_SetLogToFile(3, path, true);
//            }
//        }
//        if (ConstantsFace.HK_PLAY_SDK == null) {
//            if (createPlayInstance()) {
//                log.info("[HK]playSdk载入成功----------");
//            } else {
//                log.error("[HK]playSdk初始化失败----------");
//            }
//        }
//        return result;
//    }
//
//    @Override
//    public boolean login(String ip, int port, String userName, String password) {
//        boolean result = true;
//        if (ConstantsFace.HK_CAMERA_DRIVER_MAP.containsKey(ip)) {
//            return true;
//        }
//        try {
//            HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
//            HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
//            m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
//            System.arraycopy(ip.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, ip.length());
//            m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
//            System.arraycopy(userName.getBytes(), 0, m_strLoginInfo.sUserName, 0, userName.length());
//            m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
//            System.arraycopy(password.getBytes(), 0, m_strLoginInfo.sPassword, 0, password.length());
//            m_strLoginInfo.wPort = (short) port;
//            m_strLoginInfo.bUseAsynLogin = false;
//            m_strLoginInfo.byLoginMode = 0;//sdk登录模式
//            m_strLoginInfo.write();
//            int userId = hcNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
//            log.info("[HK]login ip:{},userId:{},channelNum:{},startChannel:{}", ip, userId, m_strDeviceInfo.struDeviceV30.byChanNum, m_strDeviceInfo.struDeviceV30.byStartChan);
//            if (userId == -1) {
//                log.error("[HK]{} login error:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//                return false;
//            }
//            HkCameraDriver hkCameraDriver = new HkCameraDriver(ip, port, userName, password, userId, m_strDeviceInfo.struDeviceV30.byChanNum, m_strDeviceInfo.struDeviceV30.byStartChan);
//            ConstantsFace.HK_CAMERA_DRIVER_MAP.put(hkCameraDriver.getIp(), hkCameraDriver);
//            SpringUtil.getApplicationContext().publishEvent(hkCameraDriver);
//        } catch (Exception e) {
//            log.error("[HK]{} login error:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//            result = false;
//        }
//        return result;
//    }
//
//    @Override
//    public MediaFileDto takePic(String ip, Integer channel, String basePath, String folder) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        int takePicChannel = Math.min(Optional.ofNullable(channel).orElse(cameraDriver.getStartChannel()), cameraDriver.getChannelNum());
//        HCNetSDK.NET_DVR_JPEGPARA jpegpara = new HCNetSDK.NET_DVR_JPEGPARA();
//        jpegpara.wPicSize = 3;
//        jpegpara.wPicQuality = 0;
//        Memory jpegBuffer = new Memory(8 * 1024 * 1024);
//        IntByReference a = new IntByReference();
//        if (!hcNetSDK.NET_DVR_CaptureJPEGPicture_NEW(cameraDriver.getUserId(), takePicChannel, jpegpara, jpegBuffer, 8 * 1024 * 1024, a)) {
//            log.error("[HK]{},channel:{},take pic failed:{}", ip, takePicChannel, hcNetSDK.NET_DVR_GetLastError());
//            throw new EquipmentException(String.format("拍照失败. [HK]%s,channel:%s,take pic failed:%s", ip, takePicChannel, hcNetSDK.NET_DVR_GetLastError()));
//        }
//        log.info("[HK]{},channel:{},take pic success,byteLength:{},", ip, takePicChannel, a.getValue());
//        //保存到本地
//        String fileFolder = basePath + File.separator + folder + File.separator;
//        String pictureName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS")+"_"+RandomUtil.randomInt(100) + ".jpeg";
//        if (!FileUtil.exist(fileFolder)) {
//            FileUtil.mkdir(fileFolder);
//        }
//        File file = FileUtil.writeBytes(jpegBuffer.getByteArray(0, a.getValue()), fileFolder + pictureName);
//        if (file.exists()) {
//            log.info("[HK]{},channel:{},save pic local success:{}", ip, takePicChannel, file.getAbsolutePath());
//        } else {
//            log.error("[HK]{},channel:{},save pic local failed:{}", ip, takePicChannel, folder + pictureName);
//            throw new EquipmentException(String.format("照片保存到本地失败. [HK]%s,channel:%s,save pic local failed:%s", ip, takePicChannel, folder + pictureName));
//        }
//        MediaFileDto dto = new MediaFileDto();
//        dto.setName(pictureName);
//        dto.setRelativePath(File.separator + folder + File.separator + pictureName);
//        dto.setAbsolutePath(file.getAbsolutePath());
//        return dto;
//    }
//
//    @Override
//    public MediaFileDto startRecord(String ip, Integer channel,String basePath,String folder) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        int recordChannel = Math.min(Optional.ofNullable(channel).orElse(cameraDriver.getStartChannel()), cameraDriver.getChannelNum());
//        //开启预览
//        Integer realPlayId = cameraDriver.getRealPlayId();
//        if (realPlayId != null) {
//            throw new EquipmentException("已经开启录制，请勿重复调用");
//        }
//        HCNetSDK.NET_DVR_PREVIEWINFO m_strClientInfo = new HCNetSDK.NET_DVR_PREVIEWINFO();
//        m_strClientInfo.lChannel = recordChannel;
//        m_strClientInfo.dwStreamType = 0;   //码流类型：0-主码流，1-子码流，2-三码流，3-虚拟码流，以此类推
//        m_strClientInfo.dwLinkMode = 0;
//        m_strClientInfo.bBlocked = 0;
//        m_strClientInfo.byPreviewMode = 0;
//        m_strClientInfo.bPassbackRecord = 0;
//        m_strClientInfo.byProtoType = 1;
//        m_strClientInfo.byVideoCodingType = 0;
//        m_strClientInfo.byNPQMode = 0;
//        m_strClientInfo.write();
//        realPlayId = hcNetSDK.NET_DVR_RealPlay_V40(cameraDriver.getUserId(), m_strClientInfo, null, null);
//        if (realPlayId == -1) {
//            log.error("[HK]{},channel:{},real play failed:{}", ip, recordChannel, hcNetSDK.NET_DVR_GetLastError());
//            throw new EquipmentException(String.format("开启预览失败.[HK]%s,channel:%s,real play failed:%s", ip, recordChannel, hcNetSDK.NET_DVR_GetLastError()));
//        }
//        cameraDriver.setRealPlayId(realPlayId);
//        log.info("[HK]{},channel:{},real play success realPlayId：{}", ip, recordChannel, realPlayId);
//        //保存到本地
//        String fileFolder = basePath + File.separator + folder + File.separator;
//        String videoName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + "_" + realPlayId + ".mp4";
//        cameraDriver.setVideoName(videoName);
//        if (!FileUtil.exist(fileFolder)) {
//            FileUtil.mkdir(fileFolder);
//        }
//        File file = new File(fileFolder + videoName);
//        if (!hcNetSDK.NET_DVR_SaveRealData(realPlayId, file.getAbsolutePath())) {
//            log.error("[HK]{},channel:{}，path:{},save real data failed:{}", ip, recordChannel, file.getAbsolutePath(), hcNetSDK.NET_DVR_GetLastError());
//            throw new EquipmentException(String.format("保存视频失败.[HK]%s,channel:%s,save real data failed:%s", ip, recordChannel, file.getAbsolutePath(), hcNetSDK.NET_DVR_GetLastError()));
//        }
//        log.info("[HK]{},channel:{},save real data success：{}", ip, recordChannel, file.getAbsolutePath());
//        MediaFileDto dto = new MediaFileDto();
//        dto.setName(videoName);
//        dto.setRelativePath(File.separator + folder + File.separator + videoName);
//        dto.setAbsolutePath(file.getAbsolutePath());
//        return dto;
//    }
//
//    @Override
//    public MediaFileDto stopRecord(String ip, Integer channel,String basePath,String folder) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        int recordChannel = Math.min(Optional.ofNullable(channel).orElse(cameraDriver.getStartChannel()), cameraDriver.getChannelNum());
//        Integer realPlayId = cameraDriver.getRealPlayId();
//        if (realPlayId == null) {
//            throw new EquipmentException("未开启预览");
//        }
//        if (!hcNetSDK.NET_DVR_StopSaveRealData(realPlayId)) {
//            log.error("[HK]{},channel:{},stop save real data failed:{}", ip, recordChannel, hcNetSDK.NET_DVR_GetLastError());
//        }
//        if (!hcNetSDK.NET_DVR_StopRealPlay(realPlayId)) {
//            log.error("[HK]{},channel:{},stop real play failed:{}", ip, recordChannel, hcNetSDK.NET_DVR_GetLastError());
//            throw new EquipmentException(String.format("停止预览视频失败.[HK]%s,channel:%s,stop real play failed:%s", ip, recordChannel, hcNetSDK.NET_DVR_GetLastError()));
//        }
//        log.info("[HK]{},channel:{},stop real play success", ip, recordChannel);
//        cameraDriver.setRealPlayId(null);
//        String fileFolder = basePath + File.separator + folder + File.separator;
//        String videoName = cameraDriver.getVideoName();
//        if (StrUtil.isBlank(videoName)){
//            log.error("[HK]{},channel:{},get videoName failed", ip, recordChannel);
//            throw new EquipmentException(String.format("请先开始录制.[HK]%s,channel:%s,get videoName failed", ip, recordChannel));
//        }
//        File file = new File(fileFolder + videoName);
//        if (!file.exists()) {
//            log.error("[HK]{},channel:{},file not exist：{}", ip, recordChannel, file.getAbsolutePath());
//            throw new EquipmentException(String.format("文件不存在. [HK]%s,channel:%s,file not exist：%s", ip, recordChannel, file.getAbsolutePath()));
//        }
//        cameraDriver.setVideoName(null);
//        MediaFileDto dto = new MediaFileDto();
//        dto.setName(file.getName());
//        dto.setRelativePath(File.separator + folder + File.separator + videoName);
//        dto.setAbsolutePath(file.getAbsolutePath());
//        return dto;
//    }
//
//    @Override
//    public boolean ptzCtrl(PtzCtrlDTO dto) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(dto.getIp());
//        Integer ptzChannel = Optional.ofNullable(dto.getChannel()).orElse(cameraDriver.getStartChannel());
//        Integer flag = Optional.ofNullable(dto.getFlag()).orElse(1);
//        if (!hcNetSDK.NET_DVR_PTZControl_Other(cameraDriver.getUserId(), ptzChannel, dto.getCtrlType(), flag)) {
//            log.error("[HK]{},channel:{},ptz cmd:{},flag:{},failed:{}", cameraDriver.getIp(), ptzChannel, dto.getCtrlType(), flag, hcNetSDK.NET_DVR_GetLastError());
//            throw new EquipmentException(String.format("控制失败. [HK]%s,channel:%s,ptz cmd:%s,flag:%s,failed:%s", cameraDriver.getIp(), ptzChannel, dto.getCtrlType(), flag, hcNetSDK.NET_DVR_GetLastError()));
//        }
//        log.info("[HK]{},channel:{},ptz cmd:{},flag:{},success", cameraDriver.getIp(), ptzChannel, dto.getCtrlType(), flag);
//        return Boolean.TRUE;
//    }
//
//    @Override
//    public List<Integer> initRegionAndStartMonitor(InitRegionMeasureDTO dto) {
//        try {
//            HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(dto.getIp());
//            if (cameraDriver.getThermometryMode() == 1) {
//                //专家模式需要设置规则
//                //设置预置点
//                this.NET_DVR_PTZPreset_Other(cameraDriver.getIp(), cameraDriver.getChannelNum(), 8, 1);
//                this.NET_DVR_PTZPreset_Other(cameraDriver.getIp(), cameraDriver.getChannelNum(), 39, 1);
//                //绑定规则
//                this.setRegion(cameraDriver, dto.getTemplateAreas(), false);
//            }
//            //开启测温
//            HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = new HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
//            struThermCond.byRuleID = (byte) 0;//获取全部规则
//            struThermCond.byMode = 1;
//            struThermCond.dwChan = cameraDriver.getChannelNum();
//            struThermCond.dwSize = struThermCond.size();
//            struThermCond.write();
//            synchronized (HkTemperatureCallBack.class) {
//                if (ConstantsFace.hkTemperatureCallBack == null) {
//                    ConstantsFace.hkTemperatureCallBack = new HkTemperatureCallBack();
//                }
//            }
//            Pointer pUserData = cameraDriver.getPUserData();
//            int stopThermometryHandle = hcNetSDK.NET_DVR_StartRemoteConfig(cameraDriver.getUserId(), 3629,
//                    struThermCond.getPointer(), struThermCond.size(), ConstantsFace.hkTemperatureCallBack, pUserData);
//            if (stopThermometryHandle == -1) {
//                log.error("[HK]{} startMonitor failed:{}", dto.getIp(), hcNetSDK.NET_DVR_GetLastError());
//                return null;
//            }
//            log.info("[HK]{} startMonitor success", dto.getIp());
//            cameraDriver.setStopThermometryHandle(stopThermometryHandle);
//            Integer size = Math.max(1,Optional.ofNullable(dto).map(InitRegionMeasureDTO::getTemplateAreas).map(List::size).orElse(1));
//            return IntStream.rangeClosed(1, size).boxed().collect(Collectors.toList());
//        } catch (Exception e) {
//            log.error("[HK]{} login error:{}", dto.getIp(), hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//    }
//
//    @Override
//    public AreaTemplateDTO stopRegionMonitor(InitRegionMeasureDTO dto) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(dto.getIp());
//        Integer stopThermometryHandle = cameraDriver.getStopThermometryHandle();
//        if (stopThermometryHandle != null) {
//            if (hcNetSDK.NET_DVR_StopRemoteConfig(stopThermometryHandle)) {
//                log.info("[HK]{} stop Monitor success", dto.getIp());
//                cameraDriver.setStopThermometryHandle(null);
//                if (cameraDriver.getThermometryMode() == 1) {
//                    this.setRegion(cameraDriver, null, true);
//                }
//            } else {
//                log.error("[HK]{} stop Monitor failed:{}", dto.getIp(), hcNetSDK.NET_DVR_GetLastError());
//                throw new EquipmentException(String.format("[HK]%s stop Monitor failed:%s", dto.getIp(), hcNetSDK.NET_DVR_GetLastError()));
//            }
//        }
//        if (ConstantsFace.TEMPERATURE_TABLE.isEmpty()){
//            return new AreaTemplateDTO();
//        }
//        return ConstantsFace.TEMPERATURE_TABLE.get(dto.getIp(),dto.getRuleIdList().get(0));
//    }
//
//
//
//
//    @Override
//    public CameraParamDTO getCameraParam(QueryCameraParamDTO dto) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(dto.getIp());
//        Integer ptzChannel = Optional.ofNullable(dto.getChannel()).orElse(cameraDriver.getStartChannel());
//        HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG ptzAbsoluteExParam = this.getPTZAbsoluteExParam(cameraDriver.getIp(), cameraDriver.getUserId(), ptzChannel);
//        HCNetSDK.NET_DVR_FOCUSMODE_CFG focusModeParam = this.getFocusModeParam(cameraDriver.getIp(), cameraDriver.getUserId(), ptzChannel);
//        //HCNetSDK.NET_DVR_AEMODECFG aeModeParam = this.getAeModeParam(cameraDriver.getIp(), cameraDriver.getUserId(), ptzChannel);
//        //HCNetSDK.NET_DVR_CAMERAPARAMCFG_EX ccdParam = this.getCCDParam(cameraDriver.getIp(), cameraDriver.getUserId(), ptzChannel);
//        String tmp = this.getPtzInfoXml(cameraDriver.getIp(), cameraDriver.getUserId(), ptzChannel);
//        try {
//            this.test(cameraDriver.getUserId());
//        }catch (Exception e) {
//
//        }
//
//        CameraParamDTO cameraParamDto = new CameraParamDTO();
//        if (ptzAbsoluteExParam != null) {
//            cameraParamDto.setFPan(ptzAbsoluteExParam.struPTZCtrl.fPan);
//            cameraParamDto.setFTilt(ptzAbsoluteExParam.struPTZCtrl.fTilt);
//            cameraParamDto.setFZoom(ptzAbsoluteExParam.struPTZCtrl.fZoom);
//            cameraParamDto.setDwFocus(ptzAbsoluteExParam.struPTZCtrl.dwFocus);
//            cameraParamDto.setDwFocalLen(ptzAbsoluteExParam.dwFocalLen);
//            cameraParamDto.setByZoomType(ptzAbsoluteExParam.byZoomType);
//        }
//        if (focusModeParam != null) {
//            cameraParamDto.setByFocusMode(focusModeParam.byFocusMode);
//            cameraParamDto.setDwFocusPos(focusModeParam.dwFocusPos);
//        }
////        if (aeModeParam != null) {
////            cameraParamDto.setByExposureModeSet(aeModeParam.byExposureModeSet);
////            cameraParamDto.setIIrisSet(aeModeParam.iIrisSet);
////            cameraParamDto.setIGainSet(aeModeParam.iGainSet);
////            cameraParamDto.setIGainLimit(aeModeParam.iGainLimit);
////            cameraParamDto.setByShutterSet(aeModeParam.byShutterSet);
////        }
////        if (ccdParam != null) {
////            cameraParamDto.setBySceneMode(ccdParam.bySceneMode);
////        }
//        if (StrUtil.isNotBlank(tmp)) {
//            JSONObject jsonObject = XML.toJSONObject(tmp);
//            cameraParamDto.setAbsoluteZoom(jsonObject.getJSONObject("PTZStatus").getJSONObject("AbsoluteHigh").getInt("absoluteZoom"));
//            cameraParamDto.setAzimuth(jsonObject.getJSONObject("PTZStatus").getJSONObject("AbsoluteHigh").getInt("azimuth"));
//            cameraParamDto.setElevation(jsonObject.getJSONObject("PTZStatus").getJSONObject("AbsoluteHigh").getInt("elevation"));
//        }
//        cameraParamDto.setPointSn(0);
//        cameraParamDto.setIp(cameraDriver.getIp());
//        cameraParamDto.setChannel(ptzChannel);
//        return cameraParamDto;
//    }
//
//    @Override
//    public boolean setCameraParam(CameraParamDTO dto) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(dto.getIp());
//        Integer ptzChannel = Optional.ofNullable(dto.getChannel()).orElse(cameraDriver.getStartChannel());
//        //设置对焦模式
//        this.setFocusModeParam(dto.getIp(), cameraDriver.getUserId(), ptzChannel, dto);
//        if (!dto.isOnlyChangeMode()) {
//            //设置焦距和云台角度
//            if (Objects.equals(dto.getByFocusMode(), (byte) 1)) {
//                this.setPTZAbsoluteExParam(dto.getIp(), cameraDriver.getUserId(), ptzChannel, dto);
//            } else {
//                this.setPtzInfoXml(dto.getIp(), cameraDriver.getUserId(), ptzChannel, dto.getElevation(), dto.getAzimuth(), dto.getAbsoluteZoom());
//            }
//        }
//        return Boolean.TRUE;
//    }
//
//
//    @Override
//    public boolean setAlarm(String ip) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        synchronized (HkAlarmMessageCallBack.class) {
//            if (ConstantsFace.hkAlarmMessageCallBack == null) {
//                ConstantsFace.hkAlarmMessageCallBack = new HkAlarmMessageCallBack();
//            }
//        }
//        //设置回调函数
//        Pointer pUserData = cameraDriver.getPUserData();
//        if (!hcNetSDK.NET_DVR_SetDVRMessageCallBack_V31(ConstantsFace.hkAlarmMessageCallBack, pUserData)) {
//            log.error("[HK]{} set alarm callback failed:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//            return false;
//        } else {
//            log.info("[HK]{} set alarm callback success", ip);
//        }
//        //已布防
//        if (cameraDriver.getAlarmId() != null) {
//            log.info("[HK]{} already set alarm", ip);
//            return true;
//        }
//        //报警布防参数设置
//        HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
//        m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
//        m_strAlarmInfo.byLevel = 1;  //布防等级
//        m_strAlarmInfo.byAlarmInfoType = 1;   // 智能交通报警信息上传类型：0- 老报警信息（NET_DVR_PLATE_RESULT），1- 新报警信息(NET_ITS_PLATE_RESULT)
//        m_strAlarmInfo.byDeployType = 1;   //布防类型：0-客户端布防，1-实时布防
//        m_strAlarmInfo.byAlarmTypeURL = 1 << 1;
//        m_strAlarmInfo.write();
//        int res = hcNetSDK.NET_DVR_SetupAlarmChan_V41(cameraDriver.getUserId(), m_strAlarmInfo);
//        log.info("lAlarmHandle: " + res);
//        if (res == -1) {
//            log.error("[HK]{} set Alarm failed:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//            return false;
//        } else {
//            cameraDriver.setAlarmId(res);
//            log.info("[HK]{} set Alarm success", ip);
//            return true;
//        }
//    }
//
//    @Override
//    public boolean closeAlarm(String ip) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        Integer alarmId = cameraDriver.getAlarmId();
//        if (alarmId != null) {
//            if (!hcNetSDK.NET_DVR_CloseAlarmChan(alarmId)) {
//                log.error("[HK]{} close Alarm failed:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//            }
//            cameraDriver.setAlarmId(null);
//        }
//        log.info("[HK]{} close Alarm success", ip);
//        return true;
//    }
//
//    @Override
//    public boolean position3D(String ip, int x1, int y1, int x2, int y2) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        HCNetSDK.NET_DVR_POINT_FRAME net_dvr_point_frame = new HCNetSDK.NET_DVR_POINT_FRAME();
////        该结构体中的坐标值与当前预览显示框的大小有关，现假设预览显示框为352*288，我们规定原点为预览显示框左上角的顶点，前四个参数计算方法如下:
////        xTop = 鼠标当前所选区域的起始点坐标的值*255/352；
////        xBottom = 鼠标当前所选区域的结束点坐标的值*255/352；
////        yTop = 鼠标当前所选区域的起始点坐标的值*255/288；
////        yBottom = 鼠标当前所选区域的结束点坐标的值*255/288；
////        缩小条件：xTop减去xBottom的值大于2。放大条件：xTop小于xBottom。
//        //fixme 目前是分辨率1920*1080写死的
//        int width = 1920;//1920
//        int height = 1080;//1080
//        net_dvr_point_frame.xTop = x1 * 255 / width;
//        net_dvr_point_frame.yTop = y1 * 255 / height;
//        net_dvr_point_frame.xBottom = x2 * 255 / width;
//        net_dvr_point_frame.yBottom = y2 * 255 / height;
//        if (!hcNetSDK.NET_DVR_PTZSelZoomIn_EX(cameraDriver.getUserId(), cameraDriver.getStartChannel(), net_dvr_point_frame)) {
//            log.error("[HK]{} position 3D failed:{},({},{})({},{})", ip, hcNetSDK.NET_DVR_GetLastError(), x1, y1, x2, y2);
//            return false;
//        }
//        log.info("[HK]{} position 3D success,({},{})({},{})", ip, x1, y1, x2, y2);
//        return true;
//    }
//
//    @Override
//    public boolean setRegionalFocus(String ip, int x1, int y1, int x2, int y2) {
//        HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        String requestUrL = HCNetSDK.SET_REGIONAL_FOCUS_URL.replace("channelValue", String.valueOf(cameraDriver.getStartChannel()));
//        //fixme 目前是分辨率1920*1080写死的
//        int width = 1920;
//        int height = 1080;
//        try {
//            Document document = DocumentHelper.parseText(ConstantsFace.HK_SET_REGIONAL_FOCUS_XML);
//            //坐标 0-1000
//            document.getRootElement().element("StartPoint").element("positionX").setText(String.valueOf(Math.max(Math.min(x1 * 1000 / width, 1000), 0)));
//            document.getRootElement().element("StartPoint").element("positionY").setText(String.valueOf(Math.max(Math.min(y1 * 1000 / height, 1000), 0)));
//            document.getRootElement().element("EndPoint").element("positionX").setText(String.valueOf(Math.max(Math.min(x2 * 1000 / width, 1000), 0)));
//            document.getRootElement().element("EndPoint").element("positionY").setText(String.valueOf(Math.max(Math.min(y2 * 1000 / height, 1000), 0)));
//            this.sendXmlConfig(ip, cameraDriver.getUserId(), requestUrL, document.asXML());
//        } catch (Exception e) {
//            log.error("[HK]{},set regional focus failed,{}", ip, e);
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void showString(String ip, int channel, String content) {
//        try {
//            HkCameraDriver cameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//            int userId = cameraDriver.getUserId();
//            if (userId < 0) {
//                log.error("[HK]{},show string failed,userId is {}", ip, userId);
//                return;
//            }
//            HCNetSDK.NET_DVR_SHOWSTRING cfg = new HCNetSDK.NET_DVR_SHOWSTRING();
//            if (!hcNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_SHOWSTRING, channel, cfg.getPointer(), cfg.size(), new IntByReference(2048))) {
//                System.out.println("NET_DVR_GET_SHOWSTRING_V30 faild!" + " err: " + hcNetSDK.NET_DVR_GetLastError());
//                return;
//            } else {
//                System.out.println("NET_DVR_GET_SHOWSTRING_V30 succ!");
//            }
//            cfg.read();
//            int iIndex = 3;
//            byte[] tempBytes = new byte[52];
//            byte[] osd = content.getBytes("GBK");
//            System.arraycopy(osd, 0, tempBytes, 0, osd.length);
//            cfg.struStringInfo[iIndex].wShowString = 1;//1为显示，0为不显示
//            cfg.struStringInfo[iIndex].sString = tempBytes;//叠加的字符串
//            cfg.struStringInfo[iIndex].wStringSize = (short) osd.length;//字符串大小
//            // 显示范围704*576
//            cfg.struStringInfo[iIndex].wShowStringTopLeftX = 200;//坐标x
//            cfg.struStringInfo[iIndex].wShowStringTopLeftY = 600;//坐标y
//            cfg.write();
//            hcNetSDK.NET_DVR_SetDVRConfig(userId, HCNetSDK.NET_DVR_SET_SHOWSTRING, channel, cfg.getPointer(), cfg.size());
//        } catch (Exception e) {
//            log.error("[HK]{},show string failed,{}", ip, e);
//        }
//    }
//
//    @Override
//    public void run(String... args) throws Exception {
//        //jna崩溃改为抛异常
//        if (SystemUtil.getOsInfo().isWindows()) {
//            System.setProperty("jna.protected", "true");
//        }
//        log.info("os.name:{},os.version:{}", System.getProperty("os.name"), System.getProperty("os.version"));
//    }
//
//    @Override
//    public EquipmentEnum brand() {
//        return EquipmentEnum.HK;
//    }
//
//
//    /**
//     * 动态库加载
//     *
//     * @return
//     */
//    private boolean createSDKInstance() {
//        if (ConstantsFace.HK_NET_SDK == null) {
//            log.info("---system---" + SystemUtil.getOsInfo().isMac());
//            synchronized (HCNetSDK.class) {
//                String strDllPath = "";
//                try {
//                    String libPath = properties.getHk().getLibPath();
//                    if (SystemUtil.getOsInfo().isWindows())
//                        //win系统加载库路径
//                        strDllPath = libPath + "\\HCNetSDK.dll";
//                    else if (SystemUtil.getOsInfo().isLinux())
//                        //Linux系统加载库路径
//                        strDllPath = libPath + "/libhcnetsdk.so";
//                    ConstantsFace.HK_NET_SDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
//                } catch (Exception ex) {
//                    log.error("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
//                    return false;
//                }
//            }
//        }
//        return true;
//    }
//
//    /**
//     * 播放库加载
//     *
//     * @return
//     */
//    private boolean createPlayInstance() {
//        if (ConstantsFace.HK_PLAY_SDK == null) {
//            synchronized (PlayCtrl.class) {
//                String strPlayPath = "";
//                try {
//                    String libPath = properties.getHk().getLibPath();
//                    if (SystemUtil.getOsInfo().isWindows())
//                        //win系统加载库路径
//                        strPlayPath = libPath + "\\PlayCtrl.dll";
//                    else if (SystemUtil.getOsInfo().isLinux())
//                        //Linux系统加载库路径
//                        strPlayPath = libPath + "/libPlayCtrl.so";
//                        return true;
//                    //ConstantsFace.HK_PLAY_SDK = (PlayCtrl) Native.loadLibrary(strPlayPath, PlayCtrl.class);
//                } catch (Exception ex) {
//                    log.error("loadLibrary: " + strPlayPath + " Error: " + ex.getMessage());
//                    return false;
//                }
//            }
//        }
//        return true;
//    }
//
//    /**
//     * 获取测温能力集
//     */
//    public boolean getThermalCap(HkCameraDriver cameraDriver) {
//        //通常最后一个通道是测温通道
//        String thermalCap = this.getCap(cameraDriver.getIp(), cameraDriver.getUserId(), cameraDriver.getChannelNum(), 3634);
//        if (StrUtil.isBlank(thermalCap)) {
//            log.error("[HK]{}获取测温能力集失败", cameraDriver.getIp());
//            return false;
//        }
//        cameraDriver.setSupportThermometry(XML.toJSONObject(thermalCap).getJSONObject("ThermalCap").getBool("isSupportThermometry", false));
//        if (cameraDriver.isSupportThermometry()) {
//            log.info("[HK]{},支持测温", cameraDriver.getIp());
//            return true;
//        }
//        log.info("[HK]{},不支持/未开启测温", cameraDriver.getIp());
//        return false;
//    }
//
//
//    /**
//     * 通用方法-获取能力集
//     */
//    private String getCap(String ip, Integer userId, Integer channel, Integer dwAbilityType) {
//        HCNetSDK.NET_DVR_STD_ABILITY net_dvr_std_ability = new HCNetSDK.NET_DVR_STD_ABILITY();
//        net_dvr_std_ability.read();
//        //通常最后一个通道是测温通道
//        IntByReference lchannel = new IntByReference(channel);
//        Memory repBuff = new Memory(1024 * 64);
//        net_dvr_std_ability.lpCondBuffer = lchannel.getPointer();
//        net_dvr_std_ability.dwCondSize = 4;
//        net_dvr_std_ability.lpOutBuffer = repBuff;
//        net_dvr_std_ability.dwOutSize = (int) repBuff.getSize();
//        net_dvr_std_ability.lpStatusBuffer = null;
//        net_dvr_std_ability.dwStatusSize = 4;
//        net_dvr_std_ability.write();
//        if (!hcNetSDK.NET_DVR_GetSTDAbility(userId, dwAbilityType, net_dvr_std_ability)) {
//            log.error("[HK]{},获取{}能力集失败,{}", ip, dwAbilityType, hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//        net_dvr_std_ability.read();
//        String cap = net_dvr_std_ability.lpOutBuffer.getString(0);
//        //isSupportPosition3D 是否支持3D定位
//        log.info("[HK]{},{}能力集：{}", ip, dwAbilityType, cap);
//        return cap;
//    }
//
//    /**
//     * 获取测温模式能力集
//     */
//    public boolean getThermometryMode(HkCameraDriver cameraDriver) {
//        //通常最后一个通道是测温通道
//        String thermometryMode = this.getCap(cameraDriver.getIp(), cameraDriver.getUserId(), cameraDriver.getChannelNum(), 6764);
//        if (StrUtil.isBlank(thermometryMode)) {
//            log.error("[HK]{}获取测温模式能力集失败", cameraDriver.getIp());
//            return false;
//        }
//        String thermometryOpt = XML.toJSONObject(thermometryMode).getJSONObject("ThermometryMode").getJSONObject("mode").getStr("opt", "normal");
//        if (thermometryOpt.contains("expert")) {
//            //有专家模式就用专家模式
//            cameraDriver.setThermometryMode(1);
//        }
//        return true;
//    }
//
//    /**
//     * 设置测温模式
//     */
//    public void initThermometryMode(HkCameraDriver cameraDriver) {
//        try {
//            HCNetSDK.NET_DVR_STD_CONFIG lpnet_dvr_std_config = new HCNetSDK.NET_DVR_STD_CONFIG();
//            Pointer pointer = new Memory(4);
//            pointer.setInt(0, cameraDriver.getChannelNum());
//
//            HCNetSDK.NET_DVR_THERMOMETRY_MODE net_dvr_thermometry_mode = new HCNetSDK.NET_DVR_THERMOMETRY_MODE();
//            net_dvr_thermometry_mode.byMode = (byte) cameraDriver.getThermometryMode();
//            net_dvr_thermometry_mode.byThermometryROIEnabled = 0;
//            net_dvr_thermometry_mode.dwSize = net_dvr_thermometry_mode.size();
//            net_dvr_thermometry_mode.write();
//
//            lpnet_dvr_std_config.lpCondBuffer = pointer;
//            lpnet_dvr_std_config.dwCondSize = 4;
//            lpnet_dvr_std_config.lpInBuffer = net_dvr_thermometry_mode.getPointer();
//            lpnet_dvr_std_config.dwInSize = net_dvr_thermometry_mode.size();
//            lpnet_dvr_std_config.dwOutSize = 0;
//            lpnet_dvr_std_config.dwStatusSize = 0;
//            lpnet_dvr_std_config.byDataType = 0;
//            lpnet_dvr_std_config.lpXmlBuffer = "";
//            lpnet_dvr_std_config.dwXmlSize = 0;
//            lpnet_dvr_std_config.write();
//            if (!hcNetSDK.NET_DVR_SetSTDConfig(cameraDriver.getUserId(), HCNetSDK.NET_DVR_SET_THERMOMETRY_MODE, lpnet_dvr_std_config)) {
//                log.error("[HK]{} init thermometry mode failed:{}", cameraDriver.getIp(), hcNetSDK.NET_DVR_GetLastError());
//                return;
//            }
//            log.info("[HK]{} init thermometry mode success", cameraDriver.getIp());
//        } catch (Exception e) {
//            log.error("[HK]{} init thermometry mode error:{}", cameraDriver.getIp(), e.getMessage());
//        }
//    }
//
//    /**
//     * 设置测温区域
//     */
//    public void setRegion(HkCameraDriver cameraDriver, List<TemplateArea> areaTemplateMeasurements, boolean clearFlag) {
//        try {
//            HCNetSDK.NET_DVR_STD_CONFIG lpnet_dvr_std_config = new HCNetSDK.NET_DVR_STD_CONFIG();
//            String regionXml = this.changeRegionXml(areaTemplateMeasurements, clearFlag);
//
//            HCNetSDK.NET_DVR_THERMOMETRY_COND net_dvr_thermometry_cond = new HCNetSDK.NET_DVR_THERMOMETRY_COND();
//            net_dvr_thermometry_cond.dwSize = net_dvr_thermometry_cond.size();
//            net_dvr_thermometry_cond.dwChannel = cameraDriver.getChannelNum();
//            net_dvr_thermometry_cond.wPresetNo = 1;
//            net_dvr_thermometry_cond.write();
//
//            lpnet_dvr_std_config.lpCondBuffer = net_dvr_thermometry_cond.getPointer();
//            lpnet_dvr_std_config.dwCondSize = net_dvr_thermometry_cond.size();
//            lpnet_dvr_std_config.lpInBuffer = Pointer.NULL;
//            lpnet_dvr_std_config.dwInSize = 0;
//            lpnet_dvr_std_config.dwOutSize = 0;
//            lpnet_dvr_std_config.dwStatusSize = 0;
//            lpnet_dvr_std_config.byDataType = 1;
//            lpnet_dvr_std_config.lpXmlBuffer = regionXml;
//            lpnet_dvr_std_config.dwXmlSize = regionXml.length();
//            lpnet_dvr_std_config.write();
//            if (!hcNetSDK.NET_DVR_SetSTDConfig(cameraDriver.getUserId(), 3625, lpnet_dvr_std_config)) {
//                log.error("[HK]{} init Region failed：{}", cameraDriver.getIp(), hcNetSDK.NET_DVR_GetLastError());
//                return;
//            }
//            log.info("[HK]{} init Region success", cameraDriver.getIp());
//        } catch (Exception e) {
//            log.error("[HK]{} init Region error：{}", cameraDriver.getIp(), e.getMessage());
//        }
//    }
//
//    /**
//     * 修改测温区域xml文件
//     */
//    private String changeRegionXml(List<TemplateArea> areaTemplateMeasurements, boolean clearFlag) {
//        String regionXml = "";
//        Document regionDocument = null;
//        try {
//            ClassPathResource resource = new ClassPathResource("region.xml");
//            if (resource.exists()) {
//                //默认的
//                InputStream inputStream = resource.getInputStream();
//                regionDocument = saxReader.read(resource.getInputStream());
//                inputStream.close();
//            }
//            Element element = regionDocument.getRootElement().element("ThermometryRegionList");
//            List<Element> xmlRegionList = element.elements();
//            Element nowRule = xmlRegionList.get(0);
//            //xmlRegionList.remove(0);
//            xmlRegionList.clear();
//            //这边的21是海康web界面看的可以设置的个数
//            for (int i = 0; i < 21; i++) {
//                Element newRule = nowRule.createCopy();
//                if (i < Optional.ofNullable(areaTemplateMeasurements).map(List::size).orElse(0)) {
//                    TemplateArea area = areaTemplateMeasurements.get(i);
//                    String[] bottomLeft = StringUtils.split(area.getBottomLeftPos(), ",");
//                    String[] bottomRight = StringUtils.split(area.getBottomRightPos(), ",");
//                    String[] upperRight = StringUtils.split(area.getUpperRightPos(), ",");
//                    String[] upperLeft = StringUtils.split(area.getUpperLeftPos(), ",");
//                    List<String> posX = Arrays.asList(bottomLeft[0], bottomRight[0], upperRight[0], upperLeft[0]);
//                    List<String> posY = Arrays.asList(bottomLeft[1], bottomRight[1], upperRight[1], upperLeft[1]);
//                    List<Element> regionPointList = newRule.element("Region").element("RegionCoordinatesList").elements();
//                    regionPointList.get(0).element("positionX").setText(posX.get(0));
//                    regionPointList.get(0).element("positionY").setText(posY.get(0));
//                    regionPointList.get(1).element("positionX").setText(posX.get(1));
//                    regionPointList.get(1).element("positionY").setText(posY.get(1));
//                    regionPointList.get(2).element("positionX").setText(posX.get(2));
//                    regionPointList.get(2).element("positionY").setText(posY.get(2));
//                    regionPointList.get(3).element("positionX").setText(posX.get(3));
//                    regionPointList.get(3).element("positionY").setText(posY.get(3));
//                    newRule.element("id").setText(String.valueOf(i + 1));
//                    //name在画面上不显示，设置检测项名称没有意义。所以直接设置为CheckItemId，用来对应检测项；
//                    newRule.element("name").setText(String.valueOf(area.getCheckItemId()));
//                    newRule.element("enabled").setText("true");
//                } else {
//                    newRule.element("id").setText(String.valueOf(i + 1));
//                    //覆盖旧的
//                    newRule.element("enabled").setText("false");
//                    if (i == 0 && !clearFlag) {
//                        newRule.element("enabled").setText("true");
//                    }
//                }
//                xmlRegionList.add(i, newRule);
//            }
//            regionXml = regionDocument.asXML();
//        } catch (Exception e) {
//            log.error("[HK] change region XML error:{}", e.getMessage());
//        }
//        return regionXml;
//    }
//
//    /**
//     * 获取PTZ能力集
//     */
//    public boolean getPTZCap(HkCameraDriver cameraDriver) {
//        String ptzCap = this.getCap(cameraDriver.getIp(), cameraDriver.getUserId(), cameraDriver.getStartChannel(), 3619);
//        if (StrUtil.isBlank(ptzCap)) {
//            log.error("[HK]{}获取Ptz能力集失败", cameraDriver.getIp());
//            return false;
//        }
//        JSONObject jsonObject = XML.toJSONObject(ptzCap);
//        //是否支持3D定位
//        Boolean isSupportPosition3D = jsonObject.getJSONObject("PTZChanelCap").getBool("isSupportPosition3D", false);
//        cameraDriver.setSupportPosition3D(isSupportPosition3D);
//        return true;
//    }
//
//    /**
//     * 获取高精度PTZ绝对位置配置能力集
//     */
//    public boolean getPTZAbsoluteExCap(HkCameraDriver cameraDriver) {
//        String ptzAbsoluteExCap = this.getCap(cameraDriver.getIp(), cameraDriver.getUserId(), cameraDriver.getStartChannel(), 6695);
//        if (StrUtil.isBlank(ptzAbsoluteExCap)) {
//            log.error("[HK]{}获取高精度PTZ绝对位置配置能力集失败", cameraDriver.getIp());
//            return false;
//        }
//        return true;
//    }
//
//    /**
//     * 透传协议获取区域能力集
//     */
//    public String getImageCap(HkCameraDriver cameraDriver) {
//        //一般取第一个通道的
//        String ip = cameraDriver.getIp();
//        int channel = cameraDriver.getStartChannel();
//        int userId = cameraDriver.getUserId();
//        String requestUrL = hcNetSDK.GET_IMAGE_CAP_URL.replace("channelValue", String.valueOf(channel));//"GET /ISAPI/PTZCtrl/channels/"+channel+"/status";
//        String imageCap = this.sendXmlConfig(ip, userId, requestUrL, "");
//        log.info("[HK]{},get image cap:{}", ip, imageCap);
//        return imageCap;
//    }
//
//
//    private void test(Integer userId) throws IOException {
//        //GET方法测试，此透传接口适用支持的设备，不是产品通用接口
//        //String requestUrl = "GET /ISAPI/PTZCtrl/channels/1/zoomFocus";/*获取所有人脸库信息:ID*/
//        String requestUrl = "GET /ISAPI/Image/channels/1/focusConfiguration";/*获取所有人脸库信息:ID*/
//        String inputXml = "";
//
//        //POST方法测试，此透传接口适用支持的设备，不是产品通用接口
////        requestUrl = "POST /ISAPI/Intelligent/FDLib";/*创建一个人脸库，创建成功的返回结果里面包含FDID*/
////        String inputXml =
////                "<?xml version: \"1.0\" encoding=\"UTF-8\"?>" +
////                        "    <CreateFDLibList>" +
////                        "        <CreateFDLib>" +
////                        "        <id>1</id>" +
////                        "        <name>test01</name>" +
////                        "        <thresholdValue>60</thresholdValue>" +
////                        "        <customInfo/>" +
////                        "    </CreateFDLib>" +
////                        "</CreateFDLibList>";
//
//        //输入参数
//        HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
//        struXMLInput.read();
//
//        struXMLInput.dwSize = struXMLInput.size();
//
//        HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024);
//        stringRequest.read();
//
//        //输入ISAPI协议命令   批量查询人脸库命令：GET /ISAPI/Intelligent/FDLib
//        System.arraycopy(requestUrl.getBytes(), 0, stringRequest.byValue, 0, requestUrl.length());
//        stringRequest.write();
//        struXMLInput.lpRequestUrl = stringRequest.getPointer();
//        struXMLInput.dwRequestUrlLen = requestUrl.length();
//
//        //输入XML文本，GET命令不传输入文本
//        int inputDataLen = inputXml.getBytes("UTF-8").length;
//
//        if(inputDataLen > 0)
//        {
//            HCNetSDK.BYTE_ARRAY stringInBuffer = new HCNetSDK.BYTE_ARRAY(inputDataLen);
//            stringInBuffer.read();
//            System.arraycopy(inputXml.getBytes("UTF-8"), 0, stringInBuffer.byValue, 0, inputDataLen);
//            stringInBuffer.write();
//            struXMLInput.lpInBuffer = stringInBuffer.getPointer();
//            struXMLInput.dwInBufferSize = inputDataLen;
//        }
//        else
//        {
//            struXMLInput.lpInBuffer = null;
//            struXMLInput.dwInBufferSize = 0;
//        }
//
//        struXMLInput.write();
//
//        HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(8 * 1024);
//        stringXMLOut.read();
//        HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024);
//        struXMLStatus.read();
//
//        HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
//        struXMLOutput.read();
//        struXMLOutput.dwSize = struXMLOutput.size();
//        struXMLOutput.lpOutBuffer = stringXMLOut.getPointer();
//        struXMLOutput.dwOutBufferSize = stringXMLOut.size();
//        struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer();
//        struXMLOutput.dwStatusSize = struXMLStatus.size();
//        struXMLOutput.write();
//
//        if (!hcNetSDK.NET_DVR_STDXMLConfig(userId, struXMLInput, struXMLOutput)) {
//            //System.err.println("NET_DVR_STDXMLConfig失败，错误号: " + iErr + "，URL: " + requestUrl);
//        } else {
//            stringXMLOut.read();
//            System.out.println("输出文本大小：" + struXMLOutput.dwReturnedXMLSize);
//            //打印输出XML文本
//            //
//            //<?xml version="1.0" encoding="UTF-8"?>
//            //<FocusConfiguration version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
//            //<focusStyle>MANUAL</focusStyle>
//            //<focusLimited>10</focusLimited>
//            //</FocusConfiguration>
//
//            String strOutXML = new String(stringXMLOut.byValue).trim();
//            System.out.println(strOutXML);
//        }
//
//    }
//
//
//
//    /**
//     * 透传协议 requestParamXml为空则为获取  不为空则为设置
//     */
//    public static String sendXmlConfig(String ip, Integer userId, String requestUrL, String requestParamXml) {
//
//        HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
//        struXMLInput.read();
//
//        struXMLInput.dwSize = struXMLInput.size();
//
//        HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024);
//        stringRequest.read();
//
//        System.arraycopy(requestUrL.getBytes(), 0, stringRequest.byValue, 0, requestUrL.length());
//        stringRequest.write();
//        struXMLInput.lpRequestUrl = stringRequest.getPointer();
//        struXMLInput.dwRequestUrlLen = requestUrL.length();
//
//        //输入XML文本，GET命令不传输入文本
//        try {
//            int inputDataLen =requestParamXml.getBytes("UTF-8").length;
//
//            if(inputDataLen > 0)
//            {
//                HCNetSDK.BYTE_ARRAY stringInBuffer = new HCNetSDK.BYTE_ARRAY(inputDataLen);
//                stringInBuffer.read();
//                System.arraycopy(requestParamXml.getBytes("UTF-8"), 0, stringInBuffer.byValue, 0, inputDataLen);
//                stringInBuffer.write();
//                struXMLInput.lpInBuffer = stringInBuffer.getPointer();
//                struXMLInput.dwInBufferSize = inputDataLen;
//            } else {
//                struXMLInput.lpInBuffer = null;
//                struXMLInput.dwInBufferSize = 0;
//            }
//
//            struXMLInput.write();
//
//            HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(8 * 1024);
//            stringXMLOut.read();
//            HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024);
//            struXMLStatus.read();
//
//            HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
//            struXMLOutput.read();
//            struXMLOutput.dwSize = struXMLOutput.size();
//            struXMLOutput.lpOutBuffer = stringXMLOut.getPointer();
//            struXMLOutput.dwOutBufferSize = stringXMLOut.size();
//            struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer();
//            struXMLOutput.dwStatusSize = struXMLStatus.size();
//            struXMLOutput.write();
//            log.info("send xmlData: " + requestParamXml);
//            boolean ret = hcNetSDK.NET_DVR_STDXMLConfig(userId, struXMLInput, struXMLOutput);
//            if (!ret) {
//                log.error("[HK]{},send xml failed:{}", ip, hcNetSDK.NET_DVR_GetLastError());
//                return null;
//            }
//            stringXMLOut.read();
//            //打印输出XML文本
//            String strOutXML = new String(stringXMLOut.byValue).trim();
//            log.info("sendXml:" +strOutXML);
//            struXMLStatus.read();
//            return strOutXML;
//        }catch (Exception e) {
//            log.info("[HK]{},send xml failed:{}", e.getMessage());
//        }
//        return null;
//    }
//
//    /**
//     * 预置点操作
//     */
//    private boolean NET_DVR_PTZPreset_Other(String ip, Integer lchannel, Integer cmd, Integer pressIndex) {
//        HkCameraDriver hkCameraDriver = ConstantsFace.HK_CAMERA_DRIVER_MAP.get(ip);
//        if (!hcNetSDK.NET_DVR_PTZPreset_Other(hkCameraDriver.getUserId(), lchannel, cmd, pressIndex)) {
//            log.error("[HK]{} ptz_preset cmd：{},failed：{}", ip, cmd, hcNetSDK.NET_DVR_GetLastError());
//            return false;
//        }
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        return true;
//    }
//
//    /**
//     * 获取高精度PTZ绝对位置配置
//     */
//    private HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG getPTZAbsoluteExParam(String ip, Integer userId, Integer channel) {
//        HCNetSDK.NET_DVR_STD_CONFIG lpnet_dvr_std_config_get = new HCNetSDK.NET_DVR_STD_CONFIG();
//        HCNetSDK.NET_PTZ_INFO net_ptz_info = new HCNetSDK.NET_PTZ_INFO();
//        net_ptz_info.write();
//        HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG net_dvr_ptzabsoluteex_cfg = new HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG();
//        net_dvr_ptzabsoluteex_cfg.struPTZCtrl = net_ptz_info;
//        net_dvr_ptzabsoluteex_cfg.write();
//        Pointer pointer = new Memory(4);
//        //通道号
//        pointer.setInt(0, channel);
//        lpnet_dvr_std_config_get.lpCondBuffer = pointer;
//        lpnet_dvr_std_config_get.dwCondSize = 4;
//        lpnet_dvr_std_config_get.lpOutBuffer = net_dvr_ptzabsoluteex_cfg.getPointer();
//        lpnet_dvr_std_config_get.dwOutSize = net_dvr_ptzabsoluteex_cfg.size();
//        lpnet_dvr_std_config_get.byDataType = 0;
//        lpnet_dvr_std_config_get.write();
//        boolean ret = hcNetSDK.NET_DVR_GetSTDConfig(userId, HCNetSDK.NET_DVR_GET_PTZABSOLUTEEX, lpnet_dvr_std_config_get);
//        if (!ret) {
//            log.error("[HK]{},channel:{},get ptz absolute param failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//        lpnet_dvr_std_config_get.read();
//        net_dvr_ptzabsoluteex_cfg.read();
//        net_ptz_info.read();
//        log.info("[HK]{},channel:{},get ptz absolute param success", ip, channel);
//        return net_dvr_ptzabsoluteex_cfg;
//    }
//
//    /**
//     * 获取聚焦模式参数
//     */
//    private HCNetSDK.NET_DVR_FOCUSMODE_CFG getFocusModeParam(String ip, Integer userId, Integer channel) {
//        //获取快球聚焦模式信息
//        HCNetSDK.NET_DVR_FOCUSMODE_CFG net_dvr_focusmode_cfg = new HCNetSDK.NET_DVR_FOCUSMODE_CFG();
//        net_dvr_focusmode_cfg.write();
//        IntByReference intByReference = new IntByReference();
//        boolean ret = hcNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_FOCUSMODECFG, channel, net_dvr_focusmode_cfg.getPointer(), net_dvr_focusmode_cfg.size(), intByReference);
//        if (!ret) {
//            log.error("[HK]{},channel:{},get focus mode failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//        net_dvr_focusmode_cfg.read();
//        return net_dvr_focusmode_cfg;
//    }
//
//    /**
//     * 获取曝光、快门参数
//     */
//    private HCNetSDK.NET_DVR_AEMODECFG getAeModeParam(String ip, Integer userId, Integer channel) {
//        //获取快球其他参数信息:曝光/增益
//        HCNetSDK.NET_DVR_AEMODECFG net_dvr_aemodecfg = new HCNetSDK.NET_DVR_AEMODECFG();
//        net_dvr_aemodecfg.write();
//        IntByReference intByReference = new IntByReference();
//        boolean ret = hcNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_AEMODECFG, channel, net_dvr_aemodecfg.getPointer(), net_dvr_aemodecfg.size(), intByReference);
//        if (!ret) {
//            log.error("[HK]{},channel:{},get ae mode failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//        net_dvr_aemodecfg.read();
//        return net_dvr_aemodecfg;
//    }
//
//    /**
//     * 获取前端参数
//     */
//    private HCNetSDK.NET_DVR_CAMERAPARAMCFG_EX getCCDParam(String ip, Integer userId, Integer channel) {
//        HCNetSDK.NET_DVR_CAMERAPARAMCFG_EX net_dvr_cameraparamcfg_ex = new HCNetSDK.NET_DVR_CAMERAPARAMCFG_EX();
//        net_dvr_cameraparamcfg_ex.write();
//        Pointer lpIpParaConfig = net_dvr_cameraparamcfg_ex.getPointer();
//        IntByReference intByReference = new IntByReference();
//        boolean ret = hcNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_CCDPARAMCFG_EX, channel, lpIpParaConfig, net_dvr_cameraparamcfg_ex.size(), intByReference);
//        if (!ret) {
//            log.error("[HK]{},channel:{},get CCD mode failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//            return null;
//        }
//        net_dvr_cameraparamcfg_ex.read();
//        return net_dvr_cameraparamcfg_ex;
//    }
//
//    /**
//     * 透传协议获取ptz角度和zoom
//     */
//    private String getPtzInfoXml(String ip, Integer userId, Integer channel) {
//        //一般取第一个通道的
//        String requestUrL = HCNetSDK.GET_FOCUS_URL.replace("channelValue", String.valueOf(channel));//"GET /ISAPI/PTZCtrl/channels/"+channel+"/status";
//        String ptzInfo = this.sendXmlConfig(ip, userId, requestUrL, "");
//        log.debug("[HK]{},get ptz xml info:{}", ip, ptzInfo);
//        return ptzInfo;
//    }
//
//
//    public boolean setZoomFocus(String ip, Integer userId, Integer channel, int dwfocusPos, int zoomPos) {
//        String requestUrL = HCNetSDK.SET_FOCUS_ZOOM_URL.replace("channelValue", String.valueOf(channel));//"GET /ISAPI/PTZCtrl/channels/"+channel+"/absolute";
//        try {
//            Document document = DocumentHelper.parseText("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
//                    "<ZoomFocus xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\">" +
//                    "<pqrsZoom>10</pqrsZoom>" +
//                    "<mnstFocus>10</mnstFocus>" +
//                    "</ZoomFocus>");
//            document.getRootElement().element("ZoomFocus").element("pqrsZoom").setText(String.valueOf(zoomPos));
//            document.getRootElement().element("ZoomFocus").element("mnstFocus").setText(String.valueOf(dwfocusPos));
//            log.info("设置相机数据:" + document.asXML());
//            this.sendXmlConfig(ip, userId, requestUrL, document.asXML());
//        } catch (Exception e) {
//            log.error("[HK]{},set PtzInfo Xml failed,{}", ip, e);
//            return false;
//        }
//        return true;
//    }
//
//    public String getZoomFocus(String ip, Integer userId, Integer channel) {
//        String requestUrL = HCNetSDK.GET_FOCUS_ZOOM_URL.replace("channelValue",
//                String.valueOf(channel));
//        String ptzInfo = this.sendXmlConfig(ip, userId, requestUrL, "");
//        //log.debug("[HK]{},get ptz xml info:{}", ip, ptzInfo);
//        log.info("[HK]get ptz zoom info:{}", ptzInfo);
//        return ptzInfo;
//    }
//
//    /**
//     * 设置聚焦模式参数
//     */
//    private boolean setFocusModeParam(String ip, Integer userId, Integer channel, CameraParamDTO dto) {
//        HCNetSDK.NET_DVR_FOCUSMODE_CFG focusModeParam = this.getFocusModeParam(ip, userId, channel);
//        //默认半自动
//        focusModeParam.byFocusMode = Optional.of(dto.getByFocusMode()).orElse((byte) 2);
//        focusModeParam.byFocusSpeedLevel = 3;
//        focusModeParam.byZoomSpeedLevel = 3;
//        focusModeParam.byFocusDefinitionDisplay = 1;
//        if (focusModeParam.byFocusMode ==1 ) {
//            focusModeParam.dwFocusPos = dto.getDwFocusPos();
//        }
//        if (dto.getByFocusMode() == 2) {
//            focusModeParam.byFocusSensitivity = 2;
//        }
//        focusModeParam.write();
//        boolean ret = hcNetSDK.NET_DVR_SetDVRConfig(userId, HCNetSDK.NET_DVR_SET_FOCUSMODECFG, channel, focusModeParam.getPointer(), focusModeParam.size());
//        if (!ret) {
//            log.error("[HK]{},channel:{},set focus mode failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//            return false;
//        }
//        log.info("[HK]{},channel:{},set focus mode success", ip, channel);
//        return true;
//    }
//
//    /**
//     * 设置高精度PTZ绝对位置配置
//     */
//    private boolean setPTZAbsoluteExParam(String ip, Integer userId, Integer channel, CameraParamDTO dto) {
//        HCNetSDK.NET_DVR_PTZABSOLUTEEX_CFG ptzAbsoluteExParam = this.getPTZAbsoluteExParam(ip, userId, channel);
//        if (ptzAbsoluteExParam != null) {
//            ptzAbsoluteExParam.struPTZCtrl.dwFocus = dto.getDwFocus();
//            ptzAbsoluteExParam.struPTZCtrl.fZoom = dto.getFZoom();
//            ptzAbsoluteExParam.struPTZCtrl.fTilt = dto.getFTilt();
//            ptzAbsoluteExParam.struPTZCtrl.fPan = dto.getFPan();
//            ptzAbsoluteExParam.struPTZCtrl.write();
//            ptzAbsoluteExParam.dwFocalLen = dto.getDwFocalLen();
//            ptzAbsoluteExParam.fHorizontalSpeed = 1000f;
//            ptzAbsoluteExParam.fVerticalSpeed = 1000f;
//            ptzAbsoluteExParam.write();
//            HCNetSDK.NET_DVR_STD_CONFIG lpnet_dvr_std_config_get = new HCNetSDK.NET_DVR_STD_CONFIG();
//            Pointer pointer = new Memory(4);
//            //通道号
//            pointer.setInt(0, channel);
//            lpnet_dvr_std_config_get.lpCondBuffer = pointer;
//            lpnet_dvr_std_config_get.dwCondSize = 4;
//            lpnet_dvr_std_config_get.lpInBuffer = ptzAbsoluteExParam.getPointer();
//            lpnet_dvr_std_config_get.dwInSize = ptzAbsoluteExParam.size();
//            lpnet_dvr_std_config_get.byDataType = 0;
//            lpnet_dvr_std_config_get.write();
//            boolean ret = hcNetSDK.NET_DVR_SetSTDConfig(userId, HCNetSDK.NET_DVR_SET_PTZABSOLUTEEX, lpnet_dvr_std_config_get);
//            if (!ret) {
//                log.error("[HK]{},channel:{},set ptz absolute param failed:{}", ip, channel, hcNetSDK.NET_DVR_GetLastError());
//                return false;
//            }
//        }
//        log.info("[HK]{},channel:{},set ptz absolute param success", ip, channel);
//        return true;
//    }
//
//
//    /**
//     * 透传协议设置ptz角度和zoom
//     */
//    private boolean setPtzInfoXml(String ip, Integer userId, Integer channel, int elevation, int azimuth, int absoluteZoom) {
//        //一般取第一个通道的
//        String requestUrL = HCNetSDK.SET_FOCUS_URL.replace("channelValue", String.valueOf(channel));//"GET /ISAPI/PTZCtrl/channels/"+channel+"/absolute";
//        try {
//            Document document = DocumentHelper.parseText(ConstantsFace.HK_SET_FOCUS_XML);
//            document.getRootElement().element("AbsoluteHigh").element("elevation").setText(String.valueOf(elevation));
//            document.getRootElement().element("AbsoluteHigh").element("azimuth").setText(String.valueOf(azimuth));
//            document.getRootElement().element("AbsoluteHigh").element("absoluteZoom").setText(String.valueOf(absoluteZoom));
//            this.sendXmlConfig(ip, userId, requestUrL, document.asXML());
//        } catch (Exception e) {
//            log.error("[HK]{},set PtzInfo Xml failed,{}", ip, e);
//            return false;
//        }
//        return true;
//    }
//
//}